package com.protobuftest.protobuf;

import java.util.Collections;
import java.util.Random;
import java.util.TreeSet;

public class Test {

	static int id0 = 1;
	static class A {
		public int id = id0++;
		public int a;//排序
		public A(int a) {
			this.a = a;
		}
		@Override
		public String toString() {
			return "a:" + a;
		}
	}
	public static void main(String[] args) {
		TreeSet<A> atree = new TreeSet<>((a1, a2)->{
			if (a1.id == a2.id) {
				return 0;
			}
			int ret = Integer.compare(a1.a, a2.a);
			if(ret == 0) {
				ret = Integer.compare(a1.id, a2.id);
			}
			return ret;
		});
		A at = null;
		for (int i = 0; i < 100000; i++) {
			A aaa = new A(new Random().nextInt());
			if (i == 10000) {
				at = aaa;
			}
			atree.add(aaa);
		}
		long t1 = System.nanoTime();
		at.id = 100000;
//		TreeSet<A> atree2 = new TreeSet<>((a1, a2)->{
//			if (a1.id == a2.id) {
//				return 0;
//			}
//			int ret = Integer.compare(a1.a, a2.a);
//			if(ret == 0) {
//				ret = Integer.compare(a1.id, a2.id);
//			}
//			return ret;
//		});
//		atree2.addAll(atree);
		atree.remove(at);
		atree.add(at);
		long t2 = System.nanoTime();
		System.out.println(t2-t1);
		
	}
}
